package com.changpay.zywy.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.changpay.zywy.R;
import com.changpay.zywy.bean.MyPartent;
import com.changpay.zywy.ui.activity.serivce.SetLowerPriceActivity;

import java.util.List;

/**
 * 文件名 : MarchieActionAdapter
 * 创建者 : MangoWang
 * 创建日期 : 2019/7/23 14:45
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */
public class MarchieActionAdapter extends BaseAdapter {
    private List<MyPartent.ListBean.ActivationInfoBean> provinceBeanList;
    private LayoutInflater layoutInflater;
    private Context mContext;
    private String member_id;
    private String truename;

    public MarchieActionAdapter(Context context, List<MyPartent.ListBean.ActivationInfoBean> provinceBeanList,String member_id,String truename) {
        this.provinceBeanList = provinceBeanList;
        mContext = context;
        this.member_id = member_id;
        this.truename = truename;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return provinceBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return provinceBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.grid_view_item_layout, null);
            holder = new ViewHolder();
            holder.iv_h9_peizhi = (ImageView) convertView.findViewById(R.id.iv_h9_peizhi);
            holder.tv_h9_one = (TextView) convertView.findViewById(R.id.tv_h9_one);
            holder.tv_h9_two = (TextView) convertView.findViewById(R.id.tv_h9_two);
            holder.tv_one_progress = (TextView) convertView.findViewById(R.id.tv_one_progress);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MyPartent.ListBean.ActivationInfoBean provinceBean = provinceBeanList.get(position);
        if (provinceBean != null) {

            setProData(
                    provinceBean,
                    holder.tv_h9_one,
                    holder.tv_h9_two,
                    holder.tv_one_progress,
                    holder.iv_h9_peizhi
            );
        }
        return convertView;
    }

    class ViewHolder {
        ImageView iv_h9_peizhi;
        TextView tv_h9_one;
        TextView tv_h9_two;
        TextView tv_one_progress;
    }


    private void setProData(
            MyPartent.ListBean.ActivationInfoBean bean_one,
            TextView one,
            TextView two,
            TextView name_view,
            ImageView iv_peizhi
    ) {
        // 1.获取数据
        String total_stock = bean_one.getTotal_stock();
        String activation = bean_one.getActivation();
        one.setText(activation);
        two.setText(total_stock);
        name_view.setText(bean_one.getName());
        if (bean_one.getState().equals("0") ) {
            iv_peizhi.setBackgroundResource(R.mipmap.icon_unsetting);
            iv_peizhi.setOnClickListener(v -> {
               Intent intent = new Intent(mContext, SetLowerPriceActivity.class);
               intent.putExtra("member_id", member_id);
               intent.putExtra("truename", truename);
               intent.putExtra("goods_id", bean_one.getGoods_id());
               intent.putExtra("gc_name", bean_one.getGc_name());
               intent.putExtra("goods_name", bean_one.getGoods_name());
               intent.putExtra("goods_serial", bean_one.getGoods_serial());
               intent.putExtra("type", "qudao");
               mContext.startActivity(intent);
            });
        } else {
            iv_peizhi.setBackgroundResource(R.mipmap.icon_setting);
        }
    }


}
